package controller.servlet.category;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import model.Category;
import model.Company;
import controller.dao.Dao_Category;
import controller.dao.Dao_Company;

public class register extends HttpServlet {
	private static final long serialVersionUID = 1L;

    public register() {
        super();
    }
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
	}

	@SuppressWarnings("unused")
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		response.setContentType("text/html");
		PrintWriter out = response.getWriter();
		Dao_Company daoC = new Dao_Company();
	    Company company = daoC.list(1);
	    if(company == null){
	    	company = new Company();
	    	company.setCnpj("1234567890");
	    	company.setCorporateName("ShoppingCart.Com, Inc.");
	    }
	    getServletContext().setAttribute("company", company);
		
		String name = request.getParameter("name");
		
		Company compy = (Company) getServletContext().getAttribute("company");
		
		Dao_Category daoe = new Dao_Category();
		Category category = new Category();

		category.setName(name);
		
		daoe.save(category);
		
		out.print("1");		
	}

}
